package ads.server;

import java.net.URI;
import java.net.URISyntaxException;
import java.rmi.RemoteException;

import org.apache.log4j.Logger;

import ads.util.PlayerInfo;

public class AccessionToPrimaryServerThread extends Thread {
	private ServerImpl server;
	private static final Logger log = Logger
			.getLogger(AccessionToPrimaryServerThread.class.getName());

	@Override
	public void run() {
		URI uri;
		try {
			uri = server.formatURI();
			log.info("Accession To Primary Server.primary server :" + uri);
		} catch (URISyntaxException e) {
			e.printStackTrace();
			log.fatal("URISyntaxException", e);
			return;
		}
		for (PlayerInfo playerInfo : server.players) {
			try {
				playerInfo.getStub().forwardConnection(uri);
			} catch (RemoteException e) {
				log.error("forward client Connection", e);
			}
		}

	}

	public AccessionToPrimaryServerThread(ServerImpl server) {
		super();
		this.server = server;
	}
}
